﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Linq.Mapping;
using ECI.Entities;
using ECI.Entities.Builder;

namespace ECI.LIP.Entities
{
    ///<summary>
    ///[SYS_MENU]
    ///</summary>
    [Serializable]
    [Table(Name = "SYS_MENU")]
    public partial class SysMenu
    {
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "MENU_ID")]
        public System.Nullable<double> MenuId { get { return this._MenuId; } set { this._MenuId = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.MenuId); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "NAME")]
        public string Name { get { return this._Name; } set { this._Name = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Name); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "URL")]
        public string Url { get { return this._Url; } set { this._Url = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Url); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "STATUS")]
        public string Status { get { return this._Status; } set { this._Status = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Status); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "SEQ")]
        public System.Nullable<double> Seq { get { return this._Seq; } set { this._Seq = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Seq); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "REMARK")]
        public string Remark { get { return this._Remark; } set { this._Remark = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Remark); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "ICON")]
        public string Icon { get { return this._Icon; } set { this._Icon = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.Icon); } }
        ///<summary>
        ///[]
        ///</summary>
        [Column(Storage = "PARENT_ID")]
        public System.Nullable<double> ParentId { get { return this._ParentId; } set { this._ParentId = value; if (this.DataModelBegin)AddEnum(SysMenuEnum.ParentId); } }

        /// <summary>
        /// ????????:???????True?,????????,?????????????????????,???????????????????????????????????
        /// </summary>
        public void StartSetSQLValue()
        {
            this.DataModelBegin = true;
        }

        /// <summary>
        /// ???????
        /// </summary>
        public void EndSetSQLValue()
        {
            this.DataModelBegin = false;
        }

        private bool DataModelBegin;
        public List<SysMenuEnum> ListEnum { get; set; }

        public void AddEnum(SysMenuEnum item)
        {
            if (ListEnum == null) ListEnum = new List<SysMenuEnum>();
            if (!ListEnum.Contains(item))
            {
                ListEnum.Add(item);
            }
        }



        private SysMenuEnum _keyField;
        public SysMenuEnum KeyField { get { return this._keyField; } }

        public void SetKeyField(SysMenuEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public SysMenu()
        {
        }

        public SysMenu(SysMenuEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public bool HasSetKeyField { get; set; }

        public SysMenuEnum SortByField { get; set; }

        public SortDirection SortDirection { get; set; }


        public string SQLUpdate
        {
            get { return new SQLBuilder<SysMenu, SysMenuEnum>().Update(this); }
        }

        public string SQLInsert
        {
            get { return new SQLBuilder<SysMenu, SysMenuEnum>().Insert(this); }
        }

        public string SQLDelete
        {
            get { return new SQLBuilder<SysMenu, SysMenuEnum>().Delete(this); }
        }

        public string SQLSelect
        {
            get { return new SQLBuilder<SysMenu, SysMenuEnum>().Select(this); }
        }

        public void SetAllEnum()
        {
            new SQLBuilder<SysMenu, SysMenuEnum>().SetAllEnum(this);
        }

        private DataTable FetchDataTable()
        {
            return FetchDataTable(null);
        }

        private DataTable FetchDataTable(object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<SysMenu, SysMenuEnum>().GetDataTable(this, ts);
        }

        /// <summary>
        /// ???????????????????FetchEntity??????
        /// </summary>
        public bool HasFetchData { get; set; }

        /// <summary>
        /// ??????????????????????FetchEntity??????
        /// </summary>
        public bool NotFetchData { get { return !HasFetchData; } }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public SysMenu FetchEntity()
        {
            return FetchEntity("", null);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public SysMenu FetchEntity(string sql)
        {
            return FetchEntity(sql, null);
        }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public SysMenu FetchEntity(object ts)
        {
            return FetchEntity("", ts);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public SysMenu FetchEntity(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<SysMenu, SysMenuEnum>().GetEntity(sql, this, ts);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <returns>??????</returns>
        public List<SysMenu> FetchEntities()
        {
            return FetchEntities("", null);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>??????</returns>		
        public List<SysMenu> FetchEntities(string sql)
        {
            return FetchEntities(sql, null);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<SysMenu> FetchEntities(object ts)
        {
            return FetchEntities("", ts);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<SysMenu> FetchEntities(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<SysMenu, SysMenuEnum>().GetEntities(sql, this, ts);
        }

        /// <summary>
        /// ?????????????
        /// </summary>
        /// <returns>True???? False??????</returns>
        public bool Exists()
        {
            return Exists(null);
        }

        /// <summary>
        ///  ?????????????
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>True???? False??????</returns>
        public bool Exists(object ts)
        {
            SysMenu item = this.FetchEntity(ts);
            return item.HasFetchData;
        }




    }


    public partial class SysMenu
    {
        private System.Nullable<double> _MenuId;
        private string _Name = "";
        private string _Url = "";
        private string _Status = "";
        private System.Nullable<double> _Seq;
        private string _Remark = "";
        private string _Icon = "";
        private System.Nullable<double> _ParentId;
    }


    public enum SysMenuEnum
    {
        ///<summary>
        ///[]
        ///</summary>
        MenuId,
        ///<summary>
        ///[]
        ///</summary>
        Name,
        ///<summary>
        ///[]
        ///</summary>
        Url,
        ///<summary>
        ///[]
        ///</summary>
        Status,
        ///<summary>
        ///[]
        ///</summary>
        Seq,
        ///<summary>
        ///[]
        ///</summary>
        Remark,
        ///<summary>
        ///[]
        ///</summary>
        Icon,
        ///<summary>
        ///[]
        ///</summary>
        ParentId
    }
}
